package cuongnh.project.japanesediary.vocabulary.ui.wizard;

import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import cuongnh.project.japanesediary.vocabulary.common.CommonServices;
import cuongnh.project.japanesediary.vocabulary.model.Vocabulary;
import cuongnh.project.japanesediary.vocabulary.ui.wizard.page.NewVocabularyWizardPage;

@Component("newVocabularyWizard")
@Scope("prototype")
public class AddVocabularyWizard extends Wizard implements INewWizard {

	private Vocabulary vocabulary;
	private NewVocabularyWizardPage page;
	private IWorkbench workbench;

	@Autowired
	private CommonServices commonServices;

	public AddVocabularyWizard() {
		setWindowTitle("New Wizard");
		this.vocabulary = new Vocabulary();
	}

	public AddVocabularyWizard(CommonServices commonServices,
			Vocabulary vocabulary) {
		setWindowTitle("New Wizard");
		this.vocabulary = vocabulary;
		this.commonServices = commonServices;
	}

	@Override
	public void addPages() {
		page = new NewVocabularyWizardPage(vocabulary);
		addPage(page);
	}

	@Override
	public boolean performFinish() {
		commonServices.getVocabularyDao().saveOrUpdate(vocabulary);
		return true;
	}

	@Override
	public void init(IWorkbench workbench, IStructuredSelection selection) {
		this.workbench = workbench;

	}
	
	public Vocabulary getVocabulary() {
		return vocabulary;
	}

}
